<template>
  <div class="global">
    <p class="del" @click="del">删除</p>
    <div class="content">
      <p class="title">{{detailData.title}}</p>
      <div class="info">
        <text class="left">发送人：{{detailData.nick_name}}</text>
        <text class="right">{{time}}</text>
      </div>
      <div class="msg_content">{{detailData.content}}</div>
    </div>
  </div>
</template>

<script>
import api from '@/utils/api'
export default {
  data () {
    return {
      detailData: {},
      noticeId: 0,
      time: ''
    }
  },
  onLoad () {
    this.noticeId = this.$root.$mp.query.noticeId
    this.opnoticedetail(this.noticeId)
  },
  methods: {
    del () {
      this.opnoticedel(this.noticeId)
    },
    opnoticedel (noticeId) {
      var param = {}
      param['notice_id'] = noticeId
      const opnoticedel = api.opnoticedel(param)
      opnoticedel.then(d => {
        if (d.code === 200) {
          wx.navigateBack()
        }
      })
      .catch((e) => {
        console.log(e)
      })
    },
    opnoticedetail (noticeId) {
      var param = {}
      param['notice_id'] = noticeId
      const opnoticedetail = api.opnoticedetail(param)
      opnoticedetail.then(d => {
        if (d.code === 200) {
          this.detailData = d.data
          var date = new Date(this.detailData.create_time * 1000)
          this.time = date.getFullYear() + '/' + ((date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) + '/' + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ' + date.getHours() + ':' + date.getMinutes()
        }
      })
      .catch((e) => {
        console.log(e)
      })
    }
  }
}
</script>

<style>
@import './sys_detail.css';
</style>
